package bTree.LeetCode;

public class 监控二叉树 {
    int cnt = 0;

    public int minCameraCover(TreeNode root) {
        int troll = troll(root);
        if (troll==1){
            cnt++;
        }
        return cnt;
    }

    private int troll(TreeNode root) {
        /**
         * 1.无覆盖
         * 2.有覆盖
         * 3.有监控
         */
        if (root==null){
            return 2;
        }
        int left=troll(root.left);
        int right=troll(root.right);
        if (left==1||right==1){
            cnt++;
            return 3;
        }
        if (left==2&&right==2){
            return 1;
        }
        if (left==3||right==3){
            return 2;
        }
        return -1;
    }
}